<?php
namespace App\Repos;
use App\Models\UserVoucher;
use DB;
use Carbon\Carbon;

class UserVoucherRepo
{
	public static function getList($where)
	{
		$list = DB::table('user_vouchers as uv')
		->select(['uv.id','sv.name','sv.value','uv.user_id','uv.end_date'])
		->leftJoin('shop_vouchers as sv','uv.shop_voucher_id','=','sv.id')
		->where($where)
		->get();
		return $list;
	}


	public static function update($where,$data)
	{
		return UserVoucher::where($where)->update($data);
	}

	/**
	 * 用户第一次登录和拍十秒送优惠券
	 */
	public static function create($data)
	{
		// 优惠券有效期 3天
		$data['end_date'] = Carbon::now()->addDays(3);
		$flag = UserVoucher::Create($data);		
		return $flag;		
	}

	public static function find($where=[])
	{
		return UserVoucher::with('shopVoucher')
							->where($where)
							->first();
	} 



	
}